﻿@*
    TicketDesk - Attribution notice
    Contributor(s):

         Stephen Redd (stephen@reddnet.net, http://www.reddnet.net)

    This file is distributed under the terms of the Microsoft Public
    License (Ms-PL). See http://opensource.org/licenses/MS-PL
    for the complete terms of use.

    For any distribution that contains code from this file, this notice of
    attribution must remain intact, and a copy of the license must be
    provided to the recipient.
*@

@using System.ComponentModel.DataAnnotations
@using System.Reflection
@using TicketDesk.PushNotifications
@model TicketDesk.PushNotifications.Model.ApplicationPushNotificationSetting.PushNotificationDeliveryProviderSetting
@{
    ViewBag.Title = "ConfigureDeliveryProvider";
}
<main>
    <div class="container">
        <div class="col-lg-8 col-lg-offset-2  col-sm-12">

            @{
                var provider = PushNotificationDeliveryManager.CreateDeliveryProviderInstance(Model);
                var provConfigPropertyInfo = provider.Configuration.GetType().GetProperties();

                using (Html.BeginForm("ConfigureDeliveryProvider", "PushNotificationSettings", FormMethod.Post, new { @class = "form-horizontal" }))
                {
                    <fieldset>

                        <!-- Form Name -->
                        <legend>Push notification settings</legend>
                        @Html.HiddenFor(model => model.ProviderAssemblyQualifiedName)
                        <div class="panel panel-info">
                            <div class="panel-heading">
                                <h2 class="panel-title">@Html.DescriptionFor(Type.GetType(Model.ProviderAssemblyQualifiedName))</h2>
                            </div>
                            <div class="panel-body ">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.IsEnabled, new { @class = "col-md-4 col-sm-4 control-label" })
                                    <div class="col-md-8 col-sm-8">
                                        <label class="checkbox-inline">
                                            @Html.EditorFor(model => model.IsEnabled)
                                            @Html.PromptFor(model => model.IsEnabled)
                                        </label>
                                        @Html.ValidationMessageFor(model => model.IsEnabled, "", new { @class = "text-danger" })
                                        @Html.DescriptionFor(model => model.IsEnabled, "help-block", "span")
                                    </div>
                                </div>

                                @foreach (var property in provConfigPropertyInfo)
                                {
                                    <div class="form-group">
                                        <label class="col-md-4 col-sm-4 control-label">@Html.DisplayNameFor(property)</label>
                                        <div class="col-md-8 col-sm-8">

                                            @{
                                                if (property.PropertyType == typeof(bool?))
                                                {
                                                    <label class="checkbox-inline">
                                                        @Html.CheckBox(property.Name, ((bool?)property.GetValue(provider.Configuration, null)) ?? false)
                                                        @Html.PromptFor(property)
                                                       
                                                    </label>
                                                }
                                                else
                                                {
                                                    var type = property.PropertyType == typeof(int?) ? "number" : "text";
                                                    var dtprop = property.GetCustomAttributes().FirstOrDefault(a => a.GetType() == typeof(DataTypeAttribute));
                                                    if (dtprop != null)
                                                    {
                                                        var dt = ((DataTypeAttribute)dtprop).DataType;
                                                        type =
                                                            dt == DataType.Password ? "password" :
                                                            dt == DataType.EmailAddress ? "email" :
                                                            type;
                                                    }
                                                    @Html.TextBox(property.Name, property.GetValue(provider.Configuration, null), new { @class = "form-control input-sm", type })
                                                    @Html.ValidationMessage(property.Name)
                                                }
                                                @Html.DescriptionFor(property, "help-block", "span")
                                            }
                                        </div>




                                    </div>
                                                }
                            </div>
                            <div class="panel-footer">

                                <button type="submit" class="btn btn-success" tabindex="10"><i class="fa fa-save"></i>&nbsp;&nbsp;Save</button>&nbsp;&nbsp;
                                @Html.ActionLink("Back to settings", "Index")
                            </div>

                        </div>
                    </fieldset>
                                                }}
        </div>
    </div>
</main>